import 'package:flutter/material.dart';
import 'package:flutter_frontend/models/list_title_model.dart';
import 'package:flutter_frontend/pages/mine/about_page.dart';
import 'package:flutter_frontend/utils/app_manager.dart';
import 'package:flutter_frontend/utils/assets_path.dart';
import 'package:flutter_frontend/utils/no_splash_scroll_behavior.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class MinePage extends StatefulWidget {
  const MinePage({Key? key}) : super(key: key);

  @override
  State<MinePage> createState() => _MinePageState();
}

class _MinePageState extends State<MinePage> {
  final List<ListTitleModel> _settingsList = [
    ListTitleModel(id: 2, title: '关于', iconPath: 'icon_update'),
  ];
  late StateSetter _rightStateSetter;
  int _selectIndex = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: false,
      appBar: AppBar(),
      body: Container(
        color: Theme.of(context).colorScheme.background,
        child: Row(children: [
          SizedBox(
            width: 650.w,
            child: Column(children: [
              Image.asset(AssetsPath.imagePath('default_header'), width: 250.w, height: 250.w),
              Text(AppManager.sharedInstance.userInfo?.fullName ?? '暂无昵称', style: Theme.of(context).textTheme.labelLarge),
              SizedBox(height: 50.w),
              Expanded(
                child: ScrollConfiguration(
                  behavior: NoSplashScrollBehavior(),
                  child: ListView.separated(
                    itemBuilder: (BuildContext context, int index) => InkWell(
                      child: Padding(
                        padding: const EdgeInsets.all(48).w,
                        child: Row(children: [
                          Image.asset(AssetsPath.imagePath(_settingsList[index].iconPath ?? ''), width: 48.w, height: 48.w),
                          SizedBox(width: 24.w),
                          Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
                            Text(_settingsList[index].title ?? '', style: Theme.of(context).textTheme.labelMedium),
                            if (_settingsList[index].subTitle != null) Text(_settingsList[index].subTitle ?? '', style: Theme.of(context).textTheme.labelSmall),
                          ]),
                        ]),
                      ),
                      onTap: () => _rightStateSetter(() {
                        _selectIndex = index;
                      }),
                    ),
                    separatorBuilder: (BuildContext context, int index) => const Divider(),
                    itemCount: _settingsList.length,
                  ),
                ),
              ),
            ]),
          ),
          const VerticalDivider(),
          Expanded(
            child: StatefulBuilder(
              builder: (BuildContext context, StateSetter setState) {
                _rightStateSetter = setState;
                if (_selectIndex == 0) {
                  return const AboutPage();
                } else {
                  return const SizedBox();
                }
              },
            ),
          ),
        ]),
      ),
    );
  }
}
